<template>
	<view class="index">
		<view v-if="curTabIndex == 0">
			<image src="../../static/indexBg.png" mode="" class="bg"></image>
			<view class="top">
				<view class="loginText">{{textChangeByTime}}</view>
				<view class="subtitle">{{loginText}}</view>
				<view class="df top-bottom">
					<view v-for="(v,i) in detailList" :key="i">
						<view class="img">
							<image class="img" :src="v.src"></image>
						</view>
						<view class="text">
						{{v.text}}
						<span>{{v.unit}}</span>
						</view>
					</view>
				</view>
			</view>
			<view class="bottom">
				<view class="farm">
					<view class="menu">
						<view class="item" v-for="(item,index) in menuList" :key="index" @click="goMenu(index)">
							<u-image :src="item.image" width="165" height="165"></u-image>
							<view>{{item.text}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 小程序 -->
		<view class="setting-container" v-if="curTabIndex == 1">
			<view class="top-box">
				<u-image width="100%" height="374rpx" src="@/static/indexBg.png"></u-image>
				<view class="avatar-box">
					<view>
						<!-- <button plain class="avatarBtn" open-type="chooseAvatar" @chooseavatar="changeAvatar"> -->
						<view class="avatar-circle">
							<u--image width="98rpx" height="98rpx" src="https://foster-use.oss-cn-chengdu.aliyuncs.com/icon/login.png"></u--image>
						</view>
						</button>
						<text class="nickName">尊敬的管理员</text>
						<!-- <input  class="nickName" type="nickname"  placeholder-style="color:#ffffff" :placeholder="userInfo.nickName" @blur="blurGet"/> -->
					</view>
				</view>
			</view>
			<!-- F3 列表 start -->
			<view class="listMenu-container">
				<u-cell-group>
					<u-cell 
					:icon="item.icon" 
					:isLink="true" 
					clickable 
					rightIcon="arrow-right" 
					:title="item.title"
					 v-for="(item,index) in listMenu" 
					 :key="index"
					 @click="handleListClick(item,index)"
					 ></u-cell>
				</u-cell-group>
			</view>
			<!-- F3 列表 end -->
		</view>
		<uni-tabbar @switch="tabSwitch"></uni-tabbar>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	export default {
		data() {
			return {
				date:null,
				curTabIndex:0,
				loginText:'欢迎登陆云认养平台',
				detailList: [{
						src: require('../../static/coordinate.png'),
						text: '',
						unit: ''
					},
					{
						src: require('../../static/temperature.png'),
						text: '',
						unit: '℃'
					},
					{
						src: require('../../static/humidity.png'),
						text: '',
						unit: '%'
					},
					{
						src: require('../../static/speed.png'),
						text: '',
						unit: '级'
					}
				],
				menuList:[
					{
						image:require('../../static/farmTasks.png'),
						text:'农场任务'
					},
					{
						image:require('../../static/orders.png'),
						text:'订单任务'
					},
					{
						image:require('../../static/baseManage.png'),
						text:'基地管理'
					},
					{
						image:require('../../static/messages.png'),
						text:'消息通知'
					},
				],
				listMenu:[
					{
						title:'退出登录',
						icon:require("@/static/personal-active.png"),
					},
					// {
					// 	title:'收货地址',
					// 	icon:require("@/static/address.png"),
					// },
					// {
					// 	title:'合同管理',
					// 	icon:require("@/static/contractIcon.png"),
					// },
					// {
					// 	title:'关于我们',
					// 	icon:require("@/static/about.png"),
					// },
				]
			}
		},
		computed: {
			textChangeByTime(){
				if(this.date){
					let time = this.date.split(' ')
					let hh = time[1].split(':')
					if(hh[0]<12){
						return '早上好！'
					}else{
						return '下午好！'
					}
				}
			}
		},
		onLoad(option) {
			// #ifdef H5
				uni.showTabBar();
				this.setTabber();
			// #endif
			this.getLocationAndWeather();
		},
		methods: {
			...mapMutations(['setUserInfo', 'setTabIndex']),
			tabSwitch(v){
				this.curTabIndex = v
			},
			goMenu(i){
				switch (i){
					case 0:
						this.navTo('scanQRcode')
						break;
					case 1:
						this.navTo('orderTask')
						break;
					case 2:
						this.navTo("baseInfo")
						break;
					case 3:
						uni.$u.toast('开发中，敬请期待')
				}
			},
			getLocationAndWeather(){
				uni.request({
					url:'https://restapi.amap.com/v3/ip?key=9a6a2dd849a6417eea115e31b30c8485',
					success: (res) => {
						if(res && res.data.status == '1'){
							uni.request({
								url:'https://restapi.amap.com/v3/weather/weatherInfo?key=9a6a2dd849a6417eea115e31b30c8485&city='+res.data.adcode,
								success: (res) => {
									console.log('天气：',res);
									this.detailList[0].text = res.data.lives[0].city
									this.detailList[1].text = res.data.lives[0].temperature
									this.detailList[2].text = res.data.lives[0].humidity
									this.detailList[3].text = res.data.lives[0].windpower
									this.date = res.data.lives[0].reporttime
								}
							})
						}else{
							uni.showToast({
								title:"天气查询失败，请刷新",
								icon:"none"
							})
						}
						
					}
				})
			},
			setTabber(){
				for(let i = 0;i<5;i++){
					if(i<4){
						uni.setTabBarItem({
							index:i,
							visible:false
						})
					}
				}
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			handleListClick(item,index){
				console.log("点击了列表菜单",item,index);
				let url 
				switch (index){
					case 0:
					uni.showModal({
						title:'提示',
						content:'确定要退出登录吗？',
						success: (res) => {
							if(res.confirm){
								uni.reLaunch({
									url:'/pages/index'
								})
							}else{
								return
							}
						},
					})
					break;
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.setting-container{
		height: 100vh;
		//设置样式
		.top-box{
			height: 374rpx;
			width: 100%;
			background-color: #17CC77;
			position: relative;
		}
		.avatar-box{
			position: absolute;
			bottom: 60rpx;
			left: 30rpx;
			.avatarBtn{
				border: 0;
			}
			.avatar-circle{
				border-radius: 50%;
				width: 98rpx;
				height: 98rpx;
				border:8rpx solid #ffffff;
				justify-content: center;
				overflow: hidden;
			}
			:nth-child(1){
				display: inline-flex;
				align-items: center;
				.nickName{
					margin-left: 30rpx;
					color: #ffffff;
					font-size: 38rpx;
				}
			}
		}
		.listMenu-container{
			background-color: #ffffff;
		}
	}
	
	
	.menu{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		.item{
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-bottom: 20rpx;
			view{
				padding: 10rpx 0;
			}
		}
	}
	.index {

		.df {
			display: flex;
		}

		.bg {
			width: 750rpx;
			height: 516rpx;
			position: relative;
			top: 0;
		}

		.top {
			position: absolute;
			top: 144rpx;
			z-index: 2;
			color: #fff;
			// margin-top: 144rpx;
			margin-left: 58rpx;

			.loginText {
				font-size: 54rpx;
				margin-bottom: 16rpx;
				font-weight: bold;
				letter-spacing: 5rpx;
			}

			.subtitle {
				letter-spacing: 5rpx;
				font-size: 26rpx;
				margin-bottom: 54rpx;
			}

			.top-bottom {
				margin-left: -58rpx;
				width: 750rpx;
				justify-content: space-around;

				.img {
					width: 40rpx;
					height: 40rpx;
					margin: auto;
					margin-bottom: 20rpx;
				}

				.text {
					font-size: 32rpx;

					span {
						margin-left: 2rpx;
						display: inline-block;
						font-size: 24rpx;
						line-height: -50rpx;
					}
				}
			}
		}

		.bottom {
			position: relative;
			margin-top: -85rpx;
			background-color: #F4F6F9;
			border-radius: 36rpx 36rpx 0rpx 0rpx;
			padding: 38rpx 30rpx;

			.title {
				justify-content: space-between;
				margin-bottom: 30rpx;

				.text {
					color: #1D1D1D;
					font-size: 32rpx;
					font-weight: bold;
				}

				.look {
					font-size: 28rpx;
					color: #17CC77;
					letter-spacing: 4rpx;
				}
			}

			.farm {
				position: relative;
				margin-bottom: 54rpx;

				.farmBg {
					width: 690rpx;
					height: 374rpx;
					border-radius: 20rpx;
				}

				.detail {
					position: absolute;
					bottom: 16rpx;
					left: 16rpx;
					width: 658rpx;
					justify-content: space-between;

					.left {
						width: 278rpx;
						height: 62rpx;
						background: rgba(255, 255, 255, 0.6);
						border-radius: 32rpx;
						box-sizing: border-box;
						padding: 14rpx 16rpx;

						image {
							width: 38rpx;
							height: 38rpx;
							margin-right: 12rpx;
						}

						.text {
							font-size: 26rpx;
							color: #1D1D1D;
						}
					}

					.right {
						width: 62rpx;
						height: 62rpx;
						background: rgba(255, 255, 255, 0.6);
						border-radius: 50%;
						box-sizing: border-box;
						padding: 15rpx;

						image {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}
			}

			.list {
				margin-bottom: 20rpx;

				.vfor {
					width: 690rpx;
					// height: 466rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.04);
					box-sizing: border-box;
					padding: 20rpx;

					.tt {
						justify-content: space-between;
						margin-bottom: 0rpx;

						.title {
							font-size: 30rpx;
							font-weight: bold;
							color: #282828;
							line-height: 60rpx;
							letter-spacing: 4rpx;
						}

						.tag {
							width: 120rpx;
							height: 60rpx;
							background: rgba(0, 122, 254, 0.1);
							border-radius: 8rpx;
							border: 1rpx solid #037AFF;
							color: #007AFF;
							font-size: 28rpx;
							text-align: center;
							line-height: 60rpx;
						}
					}

					.dd {
						margin-bottom: 29rpx;

						.img {
							width: 289rpx;
							height: 200rpx;
							border-radius: 10rpx;
							margin-right: 26rpx;
						}

						.detail {
							.com {
								margin-top: 20rpx;
								color: #1D1D1D;
								font-size: 26rpx;

								.detail-title {
									color: rgba(68, 78, 104, 0.7);
									width: 130rpx;
									white-space: nowrap;
									text-align: justify;
									text-align-last: justify;
									margin-right: 20rpx;
								}

								.text {
									width: 172rpx;
								}
							}
						}
					}

					.h1 {
						width: 650rpx;
						height: 1rpx;
						background: rgba(0, 0, 0, 0.12);
						margin-bottom: 8rpx;
					}
				}
			}
		}
	}
</style>